# -*- coding: UTF-8 -*-
from django.contrib import admin
from django.utils.translation import gettext_lazy as _
from .models import Category, Product, Attribute, AttributeValue


@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
    list_display = ['name', 'code', 'description', 'parent', 'created_at']
    list_display_links = ['name']
    search_fields = ['name', 'code', 'description']
    list_filter = ['parent', 'created_at']
    date_hierarchy = 'created_at'
    
    fieldsets = (
        (_('基本信息'), {
            'fields': ('name', 'code', 'description', 'parent')
        }),
    )


@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
    list_display = ['name', 'code', 'category', 'price', 'status', 'created_at']
    list_display_links = ['name']
    search_fields = ['name', 'code', 'description']
    list_filter = ['category', 'status', 'created_at']
    date_hierarchy = 'created_at'
    
    fieldsets = (
        (_('基本信息'), {
            'fields': ('name', 'code', 'category', 'description')
        }),
        (_('产品信息'), {
            'fields': ('price', 'status', 'image')
        }),
        (_('其他信息'), {
            'fields': ('note',),
            'classes': ('collapse',)
        }),
    )


@admin.register(Attribute)
class AttributeAdmin(admin.ModelAdmin):
    list_display = ['name', 'code', 'data_type', 'is_required', 'created_at']
    list_display_links = ['name']
    search_fields = ['name', 'code', 'description']
    list_filter = ['data_type', 'is_required', 'created_at']
    date_hierarchy = 'created_at'
    
    fieldsets = (
        (_('基本信息'), {
            'fields': ('name', 'code', 'description', 'data_type')
        }),
        (_('属性设置'), {
            'fields': ('is_required', 'default_value')
        }),
    )


@admin.register(AttributeValue)
class AttributeValueAdmin(admin.ModelAdmin):
    list_display = ['product', 'attribute', 'value', 'created_at']
    list_filter = ['attribute', 'created_at']
    search_fields = ['product__name', 'attribute__name', 'value']
    date_hierarchy = 'created_at'
    
    fieldsets = (
        (_('属性值'), {
            'fields': ('product', 'attribute', 'value')
        }),
    ) 